package cn.waka.sys.admin.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.waka.sys.admin.object.Channel;

@Mapper
public interface ChannelDao {

    @Select("select c.id,c.name,a.name as appName,c.channel,c.c_time as createTime,c.desc,m1.name operator  from b_channel c left join b_app a on c.app_id=a.id left join b_merchant m1 on c.operator=m1.id   order by c.id desc limit #{start},#{size}")
    List<Map<String, Object>> findPage(@Param("start") int start, @Param("size") int size);

    @Select("select count(1) from b_channel")
    int findTotal();

    @Insert("insert into b_channel(name,channel,app_id,c_time,`desc`,operator)values(#{name},#{channel},#{appId},#{createTime},#{desc},#{operator})")
    int insert(Channel o);

    @Update("update b_channel set name=#{name},channel=#{channel},app_id=#{appId},c_time=#{createTime},`desc`=#{desc},operator=#{operator} where id=#{id}")
    int update(Channel o);

    @Select("select c.id,c.name,a.name as appName,c.channel,c.c_time as createTime,c.desc,m1.id operatorId,m1.name operatorName from b_channel c left join b_app a on c.app_id=a.id left join b_merchant m1 on c.operator=m1.id  where c.id=#{id}")
    Map<String, Object> getById(int id);

    @Delete("delete from b_channel where id=#{id}")
    int del(int id);

    @Select("select max(channel)+1 from b_channel ")
    long selectMaxChannel();

    @Select("select id,channel from b_channel order by id desc")
    List<Map<String, Object>> getChannelList();
}
